from flask import Flask
import cfg
from .exts import init_exts
from .models import *

from .apis.tools_api import tools_bp
from .web_html import htmls_bp
from .utils.commons import RegexConverter

# import logging
# from logging.handlers import RotatingFileHandler
# logging.basicConfig(level=logging.WARNING)
# file_log_handler = RotatingFileHandler('logs/ih.log', maxBytes=1024*1024*100, backupCount=10)
# formatter = logging.Formatter('%(levelname)s %(filename)s:%(lineno)d %(message)s')
# file_log_handler.setFormatter(formatter)
# logging.getLogger().addHandler(file_log_handler)


def create_app():
    app = Flask(__name__, static_folder='../static')
    app.config.from_object(cfg.Development)
    init_exts(app)

    app.url_map.converters['html'] = RegexConverter

    app.register_blueprint(tools_bp)
    app.register_blueprint(htmls_bp)

    return app